/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Custom;

import java.awt.Component;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

/**
 *
 * @author Huynh Duy Khuong
 */
//http://www.roseindia.net/java/example/java/swing/CustomCellRenderer.shtml
/*getTableCellRendererComponent( JTable table, Object obj, boolean isSelected, boolean hasFocus, int row, int column):
This is the method that returns default table cell renderer. It takes the following agruments:

table: This is a JTable.
obj: This is the value that is assigning in the cells at the specified positions (rows and columns).
isSelected: When any cell is selected then it becomesl true.
hasFocus: This the the specific cell that is true when you focus any cell of a JTable.
row: This is the row of cell renderer.
column: This is the column of cell renderer.*/
public class CustomTableCellRenderer extends DefaultTableCellRenderer{
    @Override
    public Component getTableCellRendererComponent (JTable table,
Object obj, boolean isSelected, boolean hasFocus, int row, int column) {
      Component cell = super.getTableCellRendererComponent(
                         table, obj, isSelected, hasFocus, row, column);
      try{
          JLabel lb = (JLabel)obj;
          setText(lb.getText());
          setIcon(lb.getIcon());
      } catch(Exception ex) {
          
      }

      if (isSelected) {
        //cell.setBackground(Color.GRAY);
      }
      
      return cell;
    }
  }